/**
 *******************************************************************************
 * @FileName  : math.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-02-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef MATH_H_
#define MATH_H_

#include "defs_types.h"

/**
 * @brief : Set random number seed.
 * @param : seed     Pointer point to seed.
 * @return: None.
 */
void SetRandSeed(uint32_t *seed);

/**
 * @brief : Generate random number.
 * @param : None.
 * @return: 32-bit random number.
 */
uint32_t PrandNum(void);

/**
 * @brief : Generate random numbers.
 * @param : pBuf        Pointer point to buffer.
 * @param : len         the number of random.
 * @return: None.
 */
void PrandNums(uint8_t *pBuf, uint16_t len);

/**
 * @brief :
 * @param :
 * @return:
 */
uint8_t MathGetNumBitsSet(uint32_t n);

/**
 * @brief :
 * @param :
 * @return:
 */
uint8_t MathGetNumBitsSetEx(uint64_t n);

/**
 * @brief : Calculate the number of leading zeros.
 * @param : x    value
 * @return: Returns the number of leading zeros.
 */
int MathClz(uint32_t x);

/**
 * @brief : 8bits reverse.
 * @param : x    8bit data
 * @return: return reverse result.
 */
uint8_t BitReverse8(uint8_t x);

/**
 * @brief : 16bits reverse.
 * @param : x    16bit data
 * @return: return reverse result.
 */
uint16_t BitReverse16(uint16_t x);

/**
 * @brief : 32bits reverse.
 * @param : x    32bit data
 * @return: return reverse result.
 */
uint32_t BitReverse32(uint32_t x);

/**
 * @brief : Compute Hop increment.
 * @param : None.
 * @return: return Hop value.
 */
uint8_t ComputeHopInc(void);

/**
 * @brief : Compute Access Addrress.
 * @param : None.
 * @return: return Access Addrress value.
 */
uint32_t ComputeAccessAddr(void);

/**
 * @brief : Find an exponential power of 2 that is not less than x
 * @param : x
 * @return: Returns an exponential power of 2
 */
unsigned long roundup_pow_of_two(unsigned long x);

/**
 * @brief : 64bits = 32bits * 32bits
 * @param : u
 * @param : v
 * @return:
 */
uint64_t Mul64_32x32(uint32_t u, uint32_t v);

#endif /* PRAND_H_ */
